package middle;

import java.util.Stack;

public class Solution_150 {

    public int evalRPN(String[] tokens) {
        Stack<Long> stack = new Stack<>();
        for (String token : tokens) {
            Long var1, var2;
            switch (token) {
                case "+":
                    var1 = stack.pop();
                    var2 = stack.pop();
                    stack.add(var1 + var2);
                    break;
                case "-":
                    var1 = stack.pop();
                    var2 = stack.pop();
                    stack.add(var2 - var1);
                    break;
                case "*":
                    var1 = stack.pop();
                    var2 = stack.pop();
                    stack.add(var1 * var2);
                    break;
                case "/":
                    var1 = stack.pop();
                    var2 = stack.pop();
                    stack.add(var2 / var1);
                    break;
                default:
                    stack.add(Long.valueOf(token));
            }
        }
        return stack.pop().intValue();
    }

    public static void main(String[] args) {
        Solution_150 model = new Solution_150();
        System.out.println(model.evalRPN(new String[]{"2","1","+","3","*"}));
        System.out.println(model.evalRPN(new String[]{"4","13","5","/","+"}));
        System.out.println(model.evalRPN(new String[]{"10","6","9","3","+","-11","*","/","*","17","+","5","+"}));
    }
}
